package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.CourseAddNewDTO;
import cn.tedu.blackhorse.pojo.dto.JobAddNewDTO;
import cn.tedu.blackhorse.pojo.dto.JobUpdateDTO;
import cn.tedu.blackhorse.pojo.vo.JobListItemVO;
import cn.tedu.blackhorse.service.IJobService;
import cn.tedu.blackhorse.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "职责表")
@RequestMapping("/job")
public class JobController {

    @Autowired
    private IJobService jobService;

    @PostMapping("/addNew")
    @ApiOperation("新增职责")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> addNew(JobAddNewDTO jobAddNewDTO) {
        log.debug("开始处理【增加职责】的请求");
        jobService.insertJob(jobAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除职责")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理【增加职责】的请求");
        jobService.deleteJob(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改职责")
    @ApiOperationSupport(order = 400)
    public JsonResult<Void> update(Long id, JobUpdateDTO jobUpdateDTO){
        log.debug("开始处理【修改职责】的请求");
        jobService.updateJob(id,jobUpdateDTO);
        return JsonResult.ok();
    }

    @PostMapping("/")
    @ApiOperation("职责列表")
    @ApiOperationSupport(order = 500)
    public JsonResult<List<JobListItemVO>> list(){
        log.debug("开始处理【职责列表】的请求");
        List<JobListItemVO> list = jobService.list();
        return JsonResult.ok(list);
    }

}
